package zj.com.activities;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import zj.com.adapter.SelectAdapter;
import zj.com.util.LogUtils;
import zj.com.zj.R;

/**
 * Created by xi on 16/6/17.
 */
public class SelectActivity extends  BaseActivity implements View.OnClickListener{


    public ListView listView;
    public TextView title_name;
    public ImageView left_iv;
    public int type;
    public SelectAdapter adapter;
    public List<String> list;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_select);
        initView();
        initData();
    }

    public void initView(){
        list = new ArrayList<>();

        listView = (ListView) findViewById(R.id.listView);
        title_name = (TextView) findViewById(R.id.title_name);
        title_name.setText("选择");
        type = getIntent().getIntExtra("type",0);
        if(type == 0){
            list.clear();
            list.add("检查单类型1");
            list.add("检查单类型2");
            list.add("检查单类型3");

            title_name.setText("检查单类型选择");

        }else if(type == 1){
            list.clear();
            list.add("公司1");
            list.add("公司2");
            list.add("公司3");
            title_name.setText("公司选择");

        }else if(type == 2){
            list.clear();
            list.add("项目1");
            list.add("项目2");
            list.add("项目3");
            title_name.setText("检查项目选择");

        }else if(type == 3){
            list.clear();
            list.add("1分");
            list.add("2分");
            list.add("3分");
            title_name.setText("扣分选择");

        }else if(type == 4){
            list.clear();
            list.add("隐患1");
            list.add("隐患2");
            title_name.setText("隐患选择");

        }else if(type == 5){

            list.clear();
            list.add("专业1");
            list.add("专业2");
            title_name.setText("专业选择");
        }else if(type == 6){
            list.clear();
            list.add("未开始");
            list.add("施工中");
            list.add("已竣工");
            title_name.setText("施工状态");
        }

        left_iv = (ImageView) findViewById(R.id.left_iv);
        left_iv.setOnClickListener(this);
        left_iv.setVisibility(View.VISIBLE);
    }

    public void initData(){


        adapter = new SelectAdapter(list,this);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Intent intent = new Intent();
                intent.putExtra("position", position);
                LogUtils.getInstance().error("==========type==========" + position);
                setResult(RESULT_OK, intent);

                finish();

            }
        });
    }


    @Override
    public void onClick(View v) {

        switch (v.getId()){
            case R.id.left_iv:
                finish();
                break;
        }
    }
}
